<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        td{
            padding: 2px 0px;
            text-align: left;
            border: 1px solid #999;
        }
    </style>
    <script src="/resources/js/jquery-1.11.1.min.js"></script>
    <script src="/resources/js/self.js"></script>
    <script type="text/javascript" src="/resources/js/md5.js"></script>
    <script type="text/javascript" src="/resources/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="/resources/js/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js?v=2"></script>
    <script type="text/javascript" src="/resources/js/idCardUtil.js"></script>
</head>
<body>
<input type="hidden" id="id" name="id"
       class="form-control form-data ">
<input type="hidden" id="companyId" name="companyId"
       class="form-control form-data">
<table>
    <tr>
        <td colspan="6">
            <button onclick="back()" class="btn btn-primary" type="button" style="float:right;margin-right:20px;">返回</button>
        </td>
    </tr>
    <tr>
        <td width="11%"><span style="color: red">*</span>姓名</td>
        <td width="11%">
            <input type="text" id="name" name="name"
                   class="form-control form-data ">
        </td>

        <td width="11%">
            <span style="color: red">*</span>性别
        </td>
        <td width="11%">
            <select name="sex" id="sex" class="form-control form-data">
                <option value="secrecy">保密</option>
                <option value="man">男</option>
                <option value="woman">女</option>
            </select>
        </td>
        <td width="11%">
            出生年月
        </td>
        <td width="11%">
            <input type="text" id="birthDay" name="birthDay" class="form-control form-data"
                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
        </td>

    </tr>
    <tr>
        <td>
            文化程度
        </td>
        <td>
            <select name="educationLevel" id="educationLevel" class="form-control form-data">
                <option value="level0">小学以下</option>
                <option value="level1">小学</option>
                <option value="level2">初中</option>
                <option value="level3">中专/高中</option>
                <option value="level4">专科</option>
                <option value="level5">本科</option>
                <option value="level6">硕士</option>
                <option value="level7">博士</option>
            </select>
        </td>
        <td>
            民族
        </td>
        <td>
            <input type="text" id="ethnic" name="ethnic"
                   class="form-control form-data ">
        </td>

        <td>
            从业时间
        </td>
        <td>
            <input type="text" id="workYears" name="workYears" class="form-control form-data"
                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
        </td>
    </tr>
    <tr>
        <td rowspan="1">
            籍贯
        </td>
        <td rowspan="1" colspan="7">
            <input type="text" id="nativePlace" name="nativePlace"
                   class="form-control form-data ">
        </td>

    </tr>
    <tr>
        <td colspan="1">
            户籍地址
        </td>
        <td colspan="7">
            <input type="text" id="nativeAddress" name="nativeAddress"
                   class="form-control form-data ">
        </td>
    </tr>
    <tr>

        <td colspan="1">
            现在住址
        </td>
        <td colspan="7">
            <input type="text" id="address" name="address"
                   class="form-control form-data ">
        </td>
    </tr>




    <tr>
        <td>
            <span style="color: red">*</span>身份证号
        </td>
        <td >
            <input type="text" id="idCard" name="idCard"
                   data-type="idCard"
                   class="form-control form-data ">
        </td>
        <td>
            警号
        </td>
        <td >
            <input type="text" id="policeNo" name="policeNo"
                   class="form-control form-data ">
        </td>
        <td>
            电话
        </td>
        <td>
            <input type="text" id="telephone" name="telephone"
                   class="form-control form-data ">
        </td>
    </tr>

    <tr>
        <td colspan="6">
            <button onclick="save()" class="btn btn-success">提交</button>
            <button onclick="modifyPassword()" class="btn btn-primary" id="updatePassword" style="display: none;" type="button">密码重置</button>
        </td>
    </tr>

</table>
</body>
<script type="text/javascript">
    $(function () {
        setTitle("警员管理>警员维护");
        initData();
        idCardToAge();
    });
    function modifyPassword() {
        var data = getData();
        var id = data.id;
        if(isNullOrUndefined(id)){
            alert("请选择要修改的数据,并且只能选择一条");
            return;
        }
        goto("police_account_edit.html",{"id":id});
    }
    function initData(){
        var data = getData();
        var id = data.id;
        if(null2empty(id) !==""){
            $("#updatePassword").show();
            $("input[name='id']").val(id);
            $.ajax({
                url:"/admin/police/find.do",
                data:{'id':id},
                type:'post',
                dataType:'json',
                success:function(data){
                    console.log(data);
                    if(data.success){
                        initPageDate(data.data, '.form-data');

                    }
                }
            });

        }

    }
    function save() {
        var params = getPageDataByClass("form-data");
        if (strIsNull(params['name'])) {
            alert("请输入警员名称");
            return;
        }
        if (strIsNull(params['sex'])) {
            alert("请选择性别");
            return;
        }
        if (strIsNull(params['birthDay'])) {
            alert("请选择出生年月");
            return;
        }
        if (strIsNull(params['ethnic'])) {
            alert("请输入警员民族");
            return;
        }
        if (strIsNull(params['idCard'])) {
            alert("请输入警员身份证");
            return;
        }
        if (strIsNull(params['address'])) {
            alert("请输入警员现在住址");
            return;
        }
        if (strIsNull(params['idCard'])) {
            alert("请输入警员身份证号");
            return;
        }
        if (strIsNull(params['policeNo'])) {
            alert("请输入警号");
            return;
        }
        if (strIsNull(params['telephone'])) {
            alert("请输入警员联系电话");
            return;
        }

        $.ajax({
            url: "/admin/police/save.do",
            data: params,
            dataType: 'json',
            type: 'post',
            success: function (data) {
                console.log(data);
                if (data.success) {
                    alert("保存成功");
                    goto("police_list.html");
                } else {
                    alert(data.msg);
                }
            }
        });
    }
    function idCardToAge() {
        $("[data-type='idCard']").blur(function () {
            /*debugger*/
            var idCard = $(this).val();
            if(!IdentityCodeValid(idCard)){
                /*$(this).focus();*/
                $(this).val("");
                $(this).attr("placeholder","身份证错误");
            }else if(typeof($(this).attr("for-age"))!=="undefined"){
                var ageId = $(this).attr('for-age');
                var age=  GetAge(idCard);
                $(this).parent().parent().find("input[name='"+ageId+"']").val(age);
//                $("#"+ageId).val(age);
            }
        })
    }
    function back() {
        goto("police_list.html",{});
    }
</script>
</html>